package com.kgame5.xtank3d.model.cart.fsms.fire {
import kgame5.k3d.core.obj3d.bound.BBall;
import kgame5.k3d.core.obj3d.hardvo.HardVO;
import kgame5.enginex.EntityVO;
import kgame5.enginex.Entity;
import kgame5.k3d.core.math.Vector3D;
import kgame5.kmath.MathDG;

import com.kgame5.xtank3d.GameEnum;
import com.kgame5.xtank3d.control.CartBlastCommand;
import com.kgame5.xtank3d.model.tank.fsms.TankState;
import com.kgame5.xtank3d.vo.MyTankVO;

/**
 * @author kk
 */
public class StateWaitBlast extends TankState{
	
	//__________________Propetty__________________
	
	//______________________Method___________________
	public function StateWaitBlast(pvo:MyTankVO){
		super(GameEnum.STATE_EM_WAIT_BLAST, pvo);
		
	}
	
	//进入状态
	override public function enter(info:Object=null):void{
		startThink();
	}

	//执行状态
	override public function update():void{
		if(timer.isOK()){
			if(canBlast()){//检测是否可爆炸
				fsm.sendCommand(CartBlastCommand.NAME,tankVO);
			}else{
				startThink();
			}
		}
	}
	
	//退出状态
	override public function exit():void{
		
	}
	
	private function startThink():void{
		timer.start(MathDG.random(tankVO.ai.atk_think_interval_min, tankVO.ai.atk_think_interval_max));
	}
	
	private function canBlast():Boolean{
		for each(var ent:Entity in this.senceWorld.getEntityListByCateID(GameEnum.CATEID_TANK)){
			if(ent._vo.teamID == tankVO.teamID){//不杀自己人
				continue;
			}
			if(ent._vo.hardVO.HitTestBBall(tankVO.hardVO)){
				return true;
			}
		}
		return false;
	}
}//end of class
}